home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD Exchange
/
CD Exchange - Volume 1.iso
/
games
/
pd
/
chess
/
src.lha
/
src
/
gnuchess.h
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-06
|
18KB
|
605 lines
/*
* gnuchess.h - Header file for GNU CHESS
*
* Copyright (c) 1988,1989,1990 John Stanback
* Copyright (c) 1992 Free Software Foundation
*
* This file is part of GNU CHESS.
*
* GNU Chess is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* GNU Chess is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Chess; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#if !defined(__STDC__) || !defined(MSDOS)
#define const
#endif
#ifndef __GNUC__
#define inline
#endif
#include <stdio.h>
#define SEEK_SET 0
#define SEEK_END 2
#ifdef DEBUG
void
ShowDBLine (char *, short int, short int,
short int, short int, short int,
short unsigned int *);
extern FILE *debugfd;
extern short int debuglevel;
#endif /* DEBUG */
#include <ctype.h>
#ifdef MSDOS
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define RWA_ACC "r+b"
#define WA_ACC "w+b"
#else
#define RWA_ACC "r+"
#define WA_ACC "w+"
#ifndef AMIGA
#include <sys/param.h>
#endif
#include <sys/types.h>
#ifndef AMIGA
#include <sys/times.h>
#endif
#endif /* MSDOS */
#ifdef NONDSP
#define printz printf
#define scanz scanf
#else
#ifdef AMIGA
#include "amiga/amiterm.h"
#define scanz ami_scanw
extern char *libdir;
#else
#include <curses.h>
#define scanz fflush(stdout), scanw
#endif
#define printz printw
#endif
#ifndef AMIGA
#if defined(__STDC__) || defined(MSDOS)
/* <stdio.h> */
extern int fclose (FILE *);
#ifndef __ultrix /* work around bug in c89 compiler --t.mann */
extern int fscanf (FILE *, const char *, ...);
extern int fprintf (FILE *, const char *, ...);
#endif /*__ultrix*/
extern int fflush (FILE *);
/* <stdlib.h> */
extern int abs (int);
extern int atoi (const char *);
/* <time.h> */
extern long int time (long int *);
/* <string.h> */
extern void *memset (void *, int, size_t);
#endif
#endif /* AMIGA */
/* Piece values */
#define valueP 100
#define valueN 350
#define valueB 355
#define valueR 550
#define valueQ 1100
#define valueK 1200
/* masks into upper 8 bits of ataks array */
#define ctlP 0x4000
#define ctlN 0x2800
#define ctlB 0x1800
#define ctlR 0x0400
#define ctlQ 0x0200
#define ctlK 0x0100
#define ctlBQ 0x1200
#define ctlBN 0x0800
#define ctlRQ 0x0600
#define ctlNN 0x2000
/* attack functions */
#define Patak(c, u) (atak[c][u] > ctlP)
#define Anyatak(c, u) (atak[c][u] > 0)
/* distance function */
#define taxicab(a,b) taxidata[a][b]
/* hashtable flags */
#define truescore 0x0001
#define lowerbound 0x0002
#define upperbound 0x0004
#define kingcastle 0x0008
#define queencastle 0x0010
/* king positions */
#define wking PieceList[white][0]
#define bking PieceList[black][0]
#define EnemyKing PieceList[c2][0]
/* constants */
/* castle moves */
#define BLACKCASTLE 0x3C3E
#define WHITECASTLE 0x0406
#define LONGBLACKCASTLE 0x3C3A
#define LONGWHITECASTLE 0x0402
/* truth values */
#define false 0
#define true 1
/* colors */
#define white 0
#define black 1
#define neutral 2
/* piece code defines */
#define no_piece 0
#define pawn 1
#define knight 2
#define bishop 3
#define rook 4
#define queen 5
#define king 6
#define bpawn 7
/* node flags */
#define pmask 0x0007
#define promote 0x0008
#define cstlmask 0x0010
#define epmask 0x0020
#define exact 0x0040
#define pwnthrt 0x0080
#define check 0x0100
#define capture 0x0200
#define draw 0x0400
/* move symbols */
#define pxx (CP[2])
#define qxx (CP[1])
#define rxx (CP[4])
#define cxx (CP[3])
/* for everything that can't use the above */
#define Qxx " pnbrqk"
#define Pxx " PNBRQK"
#define Cxx "abcdefgh"
#define Rxx "12345678"
/***************************************************************************/
/***************** Table limits ********************************************/
/*
* ttblsz must be a power of 2. Setting ttblsz 0 removes the transposition
* tables.
*/
#if defined(MSDOS) || defined(AMIGA)
#define vttblsz 0 /*(1 << 11)*/
#else
#define vttblsz (1 << 17)
#define huge
#endif /* MSODS */
#define ttblsz vttblsz
#define TREE 1500 /* max number of tree entries */
#define MAXDEPTH 35 /* max depth a search can be carried */
#define MINDEPTH 3 /* min search depth =1 (no hint), >1 hint */
#define MAXMOVES 400 /* max number of half moves in a game */
#ifdef AMIGA
#define BOOKSIZE 10000 /* Number of unique position/move combinations allowed */
#else
#define BOOKSIZE 30000 /* Number of unique position/move combinations allowed */
#endif
#define CPSIZE 226 /* size of lang file max */
/***************** tuning paramaters **********************************************/
#define CHKDEPTH 1 /* always look forward CHKDEPTH half-moves if in check */
#define DEPTHBEYOND 11 /* Max to go beyond Sdepth */
#define HASHDEPTH 4 /* depth above which to use HashFile */
#define HASHMOVELIMIT 40 /* Use HashFile only for this many moves */
#define PTVALUE 2000 /* material value below which pawn threats at 5 & 3 are used */
#define ZDEPTH 3 /* depth beyond which to check ZDELTA for extra time */
#define ZDELTA 10 /* score delta per ply to cause extra time to be given */
#define ZNODES 1000 /* check the time every ZNODES positions */
#define MAXTCCOUNT 4 /* max number of time clicks per search */
#define MINSEARCHPCT 10 /* must have looked at MINSEARCHPCT moves on a ply on a timeout */
#define SCORETIME -50 /* score below which to add search time */
#define SCORESPLIM 8 /* Score space doesn't apply after this stage */
#define HISTORYLIM 155 /* Max value of history killer */
#define EWNDW 10 /* Eval window to force position scoring at depth greater than Sdepth + 2 */
#define WAWNDW 90 /* alpha window when computer white*/
#define WBWNDW 90 /* beta window when computer white*/
#define BAWNDW 90 /* alpha window when computer black*/
#define BBWNDW 90 /* beta window when computer black*/
#define BXWNDW 90 /* window to force position scoring at lower */
#define WXWNDW 90 /* window to force position scoring at lower */
#define DITHER 2 /* 1+max amount random can alter a pos value */
#define BBONUS 2 /* points per stage value of B increases */
#define RBONUS 6 /* points per stage value of R increases */
#define KINGPOSLIMIT ( -1) /* King positional scoring limit */
#define KINGSAFETY 16
#define MAXrehash (6)
#if defined AG0
#define WHITEAG0
#define BLACKAG0
#elif defined AG1
#define WHITEAG1
#define BLACKAG1
#elif defined AG2
#define WHITEAG2
#define BLACKAG2
#elif defined AG3
#define WHITEAG3
#define BLACKAG3
#elif defined AGB
#define WHITEAG2
#define BLACKAG2
#elif defined AG4
#define WHITEAG4
#define BLACKAG4
#endif
/************************* parameters for Opening Book *********************************/
#define BOOKBITS 10 /* # bits for hashtable to book moves */
#define BOOKFAIL 20000 /* if no book move found for BOOKFAIL turns stop using book */
#define BOOKRAND 1000 /* used to select an opening move from a list */
#define BOOKENDPCT 500 /* 50 % chance a BOOKEND will stop the book */
#define DONTUSE -32768 /* flag move as don't use */
/*************************** Book access defines ****************************************/
#define BKTBLSIZE (2<<BOOKBITS)
#define BOOKMASK (BKTBLSIZE - 1)
#define SIDEMASK 0x1
#define BOOKEND 0x2 /* means this is the last move of an opening */
#define BADMOVE 0x8000 /* means this is a bad move in this position */
/****************************************************************************************/
struct hashval
{
unsigned long key, bd;
};
struct hashentry
{
unsigned long hashbd;
unsigned short mv;
unsigned char flags, depth; /* char saves some space */
short score;
#ifdef HASHTEST
unsigned char bd[32];
#endif /* HASHTEST */
};
#ifdef HASHFILE
/*